package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传")
@RestController
@RequestMapping("admin/product")
public class FileController {

    @Autowired
    FileService fileService;

    @PostMapping("/fileUpload")
    @ApiOperation("文件上传")
    public Result fileUpLoad(@RequestPart("file") MultipartFile file) throws Exception {

        String contentType = file.getContentType();
        String filename = file.getOriginalFilename();
        String path = fileService.upload(file);
        return Result.ok(path);
    }
}
